// featurePackage/pages/myGoods/myGoods.js
const app = getApp();
import {
  myShopList,
  myShopTotalData
} from "../../../../service/jb_oa_service"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    menuTop: app.globalData.menuButton.top,
    menuHeight: app.globalData.menuButton.height,
    goodList: [
      
    ],
    isShowLoading: false,//加载状态出现
    isBottomShow: false,//是否没有更多数据了
    refreshFlag: false,
    page: 1,
    limit: 10,
    totalData: {
      "sellPrice": "0.00",
      "orderCount": 0,
      "productNum": 0,
      "settleAmount": "0.00",
      "noSettleAmount": "0.00",
      "totalSettleAmount": "0.00"
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     this.getMyShopList('refresh');
    this.getMyShopTotalData();
  },



  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  getMyShopList(type) {
    wx.showLoading();
    myShopList(this.data.page, this.data.limit).then(res => {
      wx.hideLoading();
      if (res.code == 200 && res.data) {
        let arr = (type == 'refresh' ? [] : this.data.goodList || []);
        arr = arr.concat(res.data.list || [])
        this.setData({
          goodList: arr,
          refreshFlag: false,
          isShowLoading: false,
          isBottomShow: res.data.totalPage == this.data.page ? true : false,
        })
      }
    }).catch(err => {
      wx.hideLoading();

      wx.showToast({
        title: err || '加载失败',
        icon: "none"
      })
      if (this.data.page != 1) {
        this.setData({
          page: this.data.page - 1
        })
      }
      this.setData({
        refreshFlag: false,
      })
      console.error("JJLog:orderList", err);
    })
  },
  getMyShopTotalData() {
    myShopTotalData().then(res => {
      if (res.code == 200) {
        this.setData({
          totalData: res.data || {}
        })
      }
    }).catch(err => {

    })
  },

  // 刷新数据
  handleRefresh() {
    this.setData({
      page: 1,
      isBottomShow: false,
      refreshFlag: true,
    })
    this.getMyShopList('refresh');
    this.getMyShopTotalData();
  },
  handleLoadmore() {
    if (this.data.isBottomShow) {
      return;
    }
    this.setData({
      isShowLoading: true,
      page: this.data.page + 1
    })
    this.getMyShopList();
  },




})